<!-- @format -->

<template>
  <Teleport to="body">
    <div v-if="visible">
      <div class="loading-container" v-if="type == 'full'">
        <div class="loading-content">
          <!-- 自定义 logo   -->
          <!-- <img v-if="logo" :src="logo" class="loading-logo" :alt="title" /> -->

          <!-- 加载动画 -->
          <div class="comp-loading-innerbox">
            <div class="loading-spinner">
              <div class="spinner"></div>
            </div>

            <!-- 加载文字 -->
            <div class="loading-text" v-if="type == 'full'">{{ title }}</div>
          </div>
        </div>
      </div>
      <div class="loading-spinner" v-if="type == 'small'">
        <div class="spinner"></div>
      </div>
    </div>
  </Teleport>
</template>

<script setup lang="ts">
  interface Props {
    visible?: boolean;
    logo?: string;
    title?: string;
    type?: string;
  }

  const theProps = withDefaults(defineProps<Props>(), {
    visible: true,
    title: '正在加载...',
    type: 'full', // 全屏full  局部 small
  });
</script>

<style scoped lang="scss">
  .loading-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%; // 100vh
    // background: rgba(0, 0, 0, 0.45);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 9999;
  }

  .comp-loading-innerbox {
    width: 200px;
    height: 200px;
    background-color: #fff;
    display: flex;
    justify-content: center;
    align-items: center;
    flex-wrap: wrap;
    flex-direction: column;
    gap: 12px;
    border-radius: 24px;
    box-shadow: 0 0 12px rgba(0, 0, 0, 0.2);
  }
  .loading-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
  }

  .loading-logo {
    width: 120px;
    height: auto;
    object-fit: contain;
  }

  .loading-spinner {
    position: relative;
    width: 40px;
    height: 40px;
  }
  // $main
  .spinner {
    width: 100%;
    height: 100%;
    border: 3px solid rgba($main, 0.1);
    border-top: 3px solid $main;
    border-radius: 50%;
    animation: spin 1s linear infinite;
  }

  .loading-text {
    color: #666;
    font-size: 16px;
    font-weight: 500;
  }

  @keyframes spin {
    0% {
      transform: rotate(0deg);
    }
    100% {
      transform: rotate(360deg);
    }
  }
</style>
